#!/bin/bash
#这个代码获得title－term映射后的结果
if [ $# -lt 1 ];
then
    echo "usage: getTitleTermMapedRet.sh agen_id|dis_type [dataDirPrefix]  [total_fileName]";
    exit
else
    age_id=$1
fi
if [ $# -gt 1 ];
then
    dataDirPrefix=$2    
else
    dataDirPrefix="ask"
fi
if [ $# -gt 2 ];
then
    total_file=$3
else
    total_file="src_total.txt"
fi

svdServer=172.16.10.10
svdUser=lvhongliang
preProcessPath="../preProcess"
postProcessPath="../postProcess"
getSimPath="../getsim"
splitWordPath="../splitWord"
linkAnalysePath="../link_analyse"
dataDir="/data/lvhongliang/data/"$dataDirPrefix
#
#age_id: 准备怀孕 1\n";
#        怀孕期   2\n";
#        0-1岁    3\n";
#        1-3岁    4\n";
#        3-6岁    5\n";
#        情感家庭 477\n";
#        生活消费 488\n";
#age_id=5
curDataDir=$dataDir"/"$age_id
totalFile=$curDataDir"/"$total_file
#4. 统计每个词出现的次数
echo "step 4: stat the term count  of every question!"
if [ ! -f $totalFile".title.stat" ]; then
    php $preProcessPath/statTitleWords.php $totalFile".title.split" $totalFile".title.stat" 
fi
if [ $? -ne 0 ] ; then
    echo "error"
    exit 1
fi

#7.将term，documentId映射成连续化的id
echo "step 7: make the termId and docId sequential"
termMapFile=$curDataDir"/term_id.map"
docMapFile=$curDataDir"/doc_id.map"

#获得document的数量
docNum=`wc -l $docMapFile | awk '{print $1}'`

#8. 将原来的term-document矩阵转换为termId-docId矩阵
echo "step 8: map the term-dcoment matrix to termId-docId matrix"
if [ ! -f $curDataDir"/mappedDocTerm.title.txt" ];then
    $preProcessPath/transferId.sh $totalFile".title.stat" $curDataDir"/mappedDocTerm.title.txt" $termMapFile $docMapFile 
fi
if [ $? -ne 0 ] ; then
    echo "error"
    exit 1
fi
